"""
Performs the MKV Muxing based on parts
"""
class MKVMuxer:
    trackOrder = [ 'subtitle', 'audio', 'video' ]
    outputFile = False
    defaultLanguage = { 'audio':'en', 'subtitles':'fr' }
    subtitlesByDefault = True
    tracks = { "subtitle":[], 'audio':[], 'video':[] }
    
    videoTracks = []
    audioTracks = []
    subtitlesTracks = []
    
    def __init__( self ):
        return
    
    """
    When adding a file, we need to know what tracks it contains
    Maybe it would be worth getting MKVTracks from a class that parses source
    files
    
    param MKVTrack track
    
    return track number
    """
    def addSourceFile( self, sourcefile ):
        """
        We need to keep a trace of the source => track match
        in some way. We can mux the files in any order, only tracks order
        does matter
        We also need options per track, and therefore a way to set options for
        a specific track (language, default, priority...)
        """
        for track in MKVSourceFile( self, sourcefile ):
            if ( track.type == 'video' ):
                self.videoTracks.append( track )
            elif( track.type == 'audio' ):
                self.audioTracks.append( track )
            elif( track.type == 'subtitles' ):
                self.subtitlesTracks.append( track )
        
    
"""
Represents one track in the MKV file (audio, subtitle, etc)
"""
class MKVTrack:
    type = False
    def __init__( self ):
        return

"""
A source file that will be used for a MKV
Parses the source file, and loads the tracks it contains, as self.tracks
"""
class MKVSourceFile:
    tracks = []

    def __init__( self, filename ):
        if filename.endswith( 'avi' ):
            track = MKVTrack()
            track.type = 'video'
            tracks.append( track )
            
        elif filename.endswith( 'srt' ):
            track = MKVTrack()
            track.type = 'subtitles'
            tracks.append( track )

        elif filename.endswith( 'mkv' ):
            track = MKVTrack()
            track.type = 'subtitles'
            tracks.append( track )
            
        return
    
    
mkv = MKVMuxer()
mkv.outputFile = '/path/to/outputfile'

# This gives us two tracks (video + audio)
mkv.addSourceFile( '/path/to/myvideo.mkv' )

# This gives us one track (subtitle)
mkv.addSourceFile( '/path/to/myvideo.srt' )

mkv.mux()
        
